package com.home.free.aspect;

import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Title: com.home.free.aspect<br>
 * Description: 日志切片 <br>
 * Copyright: Copyright (c) 2015<br>
 * Company: 北京云杉世界信息技术有限公司<br>
 *
 * @author gaotianjie
 * @date 2019/3/23
 */
@Aspect
@Component
public class LogServiceAspect {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Pointcut("execution(* com.home.free.service..*.*(..))")
    public void executeMethod() {
        logger.info("LogServiceAspect executeMethod ...");
    }

    @Before("executeMethod()")
    public void logBefore(JoinPoint joinPoint) {
        logger.info("LogServiceAspect 进入切片" + joinPoint.getSignature().getDeclaringTypeName() + "," + joinPoint.getSignature().getName() + JSONObject.toJSONString(joinPoint.getArgs()));
    }

    @After("executeMethod()")
    public void logAfter(JoinPoint joinPoint) {
        logger.info("LogServiceAspect 方法执行完毕" + joinPoint.getSignature().getDeclaringTypeName() + "," + joinPoint.getSignature().getName() + JSONObject.toJSONString(joinPoint.getArgs()));
    }
}
